package pro.cherish.knowledgedemoasync.service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.util.Random;

/**
 * @author 创建人：cherish
 * @version 版本号：V1.0
 * <p>
 * ***************************修订记录************************************
 * 2019-10-27 cherish 创建该类功能。
 * **********************************************************************
 * </p>
 * @ClassName 类名：TestMethod
 * @Description 功能说明：
 * <p>
 * TODO
 * </p>
 * **********************************************************************
 * @date 创建日期： 2019-10-27 cherish
 */
@Slf4j
@Service
public class TestMethod {

    public static Random random = new Random();

    @Async("testExecutor")
    public void one() throws Exception {
        log.info("第一个");
        long start = System.currentTimeMillis();
        Thread.sleep(random.nextInt(10000));
        long end = System.currentTimeMillis();
        log.info("完成一，耗时：" + (end - start) + "毫秒");
    }

    @Async("testExecutor")
    public void two() throws Exception {
        log.info("第二个");
        long start = System.currentTimeMillis();
        Thread.sleep(random.nextInt(10000));
        long end = System.currentTimeMillis();
        log.info("完成二，耗时：" + (end - start) + "毫秒");
    }

    @Async("testExecutor")
    public void three() throws Exception {
        log.info("第三个");
        long start = System.currentTimeMillis();
        Thread.sleep(random.nextInt(10000));
        long end = System.currentTimeMillis();
        log.info("完成三，耗时：" + (end - start) + "毫秒");
    }

}
